/********************************************************************************
 * MerchantAccountAction.java
 *
 * Created by Jigar Mistry
 * Last modified Date: Oct 23, 2008 10:58:53 AM by Jigar Mistry
 * Version : 0.1
 * Copyright (c) 2008 - 2009 cyberThink Infotech Pvt. Ltd., All rights reserved.
 ********************************************************************************/
package com.printeverywhere.action;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.printeverywhere.delegator.AuctionListingFeesServiceDelegator;
import com.printeverywhere.delegator.CommonFunctionDelegator;
import com.printeverywhere.dto.AuctionListingFees;
import com.printeverywhere.dto.MerchantAccount;

public class MerchantAccountAction extends AdminSystemSetup {

	/**  */
	private static final long serialVersionUID = 1L;

	private List<MerchantAccount> listMerchantAccount = new ArrayList<MerchantAccount>();

	private Map<Integer, MerchantAccount> merchantAccountMap;

	private int defaultMerchantAccount = 0;

	public String execute() throws Exception {
		this.merchantAccountMap = new HashMap<Integer, MerchantAccount>();
		this.listMerchantAccount = (List<MerchantAccount>) CommonFunctionDelegator.getAllfromtable(MerchantAccount.class.getName());

		for (MerchantAccount merchantAccount : this.listMerchantAccount) {
			if(merchantAccount.isDefaultAccount()) {
				defaultMerchantAccount = merchantAccount.getId();
			}
			this.merchantAccountMap.put(merchantAccount.getId(), merchantAccount);
		}

		return SUCCESS;
	}

	public String updateMerchantAccount() throws Exception {
		for (MerchantAccount merchantAccount : this.merchantAccountMap.values()) {
			merchantAccount.setDefaultAccount(defaultMerchantAccount == merchantAccount.getId() ? true : false);
			CommonFunctionDelegator.generalUpdatebyobj(merchantAccount);
		}
		return SUCCESS;
	}

	public List<MerchantAccount> getListMerchantAccount() {
		return listMerchantAccount;
	}

	public void setListMerchantAccount(List<MerchantAccount> listMerchantAccount) {
		this.listMerchantAccount = listMerchantAccount;
	}

	public Map<Integer, MerchantAccount> getMerchantAccountMap() {
		return merchantAccountMap;
	}

	public void setMerchantAccountMap(
			Map<Integer, MerchantAccount> merchantAccountMap) {
		this.merchantAccountMap = merchantAccountMap;
	}

	public int getDefaultMerchantAccount() {
		return defaultMerchantAccount;
	}

	public void setDefaultMerchantAccount(int defaultMerchantAccount) {
		this.defaultMerchantAccount = defaultMerchantAccount;
	}
}
